package cc.telecomdigital.tdstock.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.BaseAdapter;

/**
 * 自定义LinearLayout，用于实现不滚动ListView
 * @author ouyangzhihui
 *
 */
public class LinearLayoutForListView extends android.widget.LinearLayout
{
	private BaseAdapter			adapter;
	private OnClickListener		onClickListener		= null;
	private OnLongClickListener	onLongClickListener		= null;
	private OnFocusChangeListener	onFocusChangeListener	= null;

	public void fillLinearLayout()
	{
		int count = adapter.getCount();
		for (int i = 0; i < count; i++)
		{
			View v = adapter.getView(i, null, null);
			//			v.setFocusable(true);
			//			v.setFocusableInTouchMode(true);
			//			v.setOnFocusChangeListener(onFocusChangeListener);
			v.setOnClickListener(this.onClickListener);
			v.setOnLongClickListener(this.onLongClickListener);
//			v.setId(i);
			addView(v, i);
		}
	}

	public void updateView()
	{
		removeAllViews();
		fillLinearLayout();
	}

	public LinearLayoutForListView(Context context)
	{
		super(context);
	}

	public LinearLayoutForListView(Context context, AttributeSet attrs)
	{
		super(context, attrs);
	}

	public BaseAdapter getAdpater()
	{
		return adapter;
	}

	public void setAdapter(BaseAdapter adpater)
	{
		this.adapter = adpater;
		fillLinearLayout();
	}

	public OnClickListener getOnItemClickListner()
	{
		return onClickListener;
	}

	public void setOnItemClickListener(OnClickListener onClickListener)
	{
		this.onClickListener = onClickListener;
	}

	public OnLongClickListener getOnItemLongClickListener()
	{
		return onLongClickListener;
	}

	public void setOnItemLongClickListener(OnLongClickListener onLongClickListener)
	{
		this.onLongClickListener = onLongClickListener;
	}

	public OnFocusChangeListener getOnFocusChangeListener()
	{
		return onFocusChangeListener;
	}

	public void setOnFocusChangeListener(OnFocusChangeListener onFocusChangeListener)
	{
		this.onFocusChangeListener = onFocusChangeListener;
	}
}
